<template>
	<div>
		<div class="outDiv">
			<go-back aa='../chooseCourse/selectCouerse'></go-back>
			<scroller style='top: 0.88rem;'>
				<div>
					<Header contentTitle="方案记录"></Header>
					<div class="main">
						<div class="cardList">
							<div class="cardItem" v-for="(item, index) of cardLists" :key="index" @click="handleCardClick(index,item.scheme)">
								<div class="line_1">
									<b>最佳选课方案结果</b>
									<span>第{{lens-index}}次生成</span>
								</div>
								<div class="line_2">
									<div class="left">
										<span>生成时间</span>
										<span>{{(new Date(item.createTime)).format('yyyy-MM-dd hh:mm')}}</span>
									</div>
									<div class="right">

										<img class="imgIcon" src="~/static/iconsvgs/rightsy.png" alt="">
									</div>
								</div>
								<div class="line_3">
									<span>最佳方案数</span>
									<span>{{item.leng}}</span>
								</div>
							</div>
						</div>
					</div>
					<div style="width: 100%; height: 10vh;"></div>
				</div>
			</scroller>
		</div>
	</div>
</template>

<script>
	import Header from '~/components/Header'
	import goBack from '~/components/goBack'
	import axios1 from '~/plugins/axios1';
	import {format} from '~/plugins/filter';
	import ls from 'store2'
	export default {
		components: {
			Header,
			goBack
		},
		data() {
			return {
				cardLists: [],
				sendObj: {},
				recodeData:[],
				lens:1
			}
		},
		created() {
			this.commonJs.gologins();
		},
	
			mounted: function() {
			this.getPlanCord()
			if(this.commonJs.isTerminal()=='isAndroid'){
				if (window.history && window.history.pushState) {
				history.pushState(null, null, document.URL);
				window.addEventListener('popstate', this.fun, false); //false阻止默认事件 
			}
			}
		
		},
		destroyed() {
			// this.commonJs.xahui('../chooseCourse/selectCouerse')
			window.removeEventListener('popstate', this.fun, false);
		},
		methods: {
				fun() {
				this.$router.replace({
					path: '../chooseCourse/selectCouerse'
			
				})
			
			},
			getPlanCord() {
				axios1.post('/curricula/getSchemeRecord?userType='+ls.get('userType')).then(res => {
					if (res.code === '0') {
						if(res.data){
							this.cardLists =res.data
							this.cardLists.forEach(item=>{
								item.scheme=JSON.parse(item.scheme);
								item.leng=item.scheme.length;
							})
							this.lens=res.data.length;
							console.log('this.cardLists',this.cardLists)
						}
				
					}
				}).catch((error) => {
					this.$vux.toast.text(error);
					// this.$vux.toast.text('服务器繁忙，请稍后再试');
				})
			},
			goto(routerName, queryData) {
				this.$router.push({
					path: routerName,
					query: {
						type: queryData
					}
				});
			},
			handleCardClick(index, data) {
	
				ls.set('preUrl', 'planRecord')
				let num = this.lens-index
				// this.$store.commit('changeRecruitScrollY', scrolly) 
				this.$store.commit('changeIndexNum', num)
				// this.$store.state.indexNum
				// console.log(this.$store.state.indexNum)
				console.log('sss',num)
				this.commonJs.gosto('bestPlan', JSON.stringify(data));
			},
			// 数字1~9转换成中文
			numberTurnChinese(num) {
				let result = '';
				switch (num) {
					case 1:
						result = '一';
						break;
					case 2:
						result = '二';
						break;
					case 3:
						result = '三';
						break;
					case 4:
						result = '四';
						break;
					case 5:
						result = '五';
						break;
					case 6:
						result = '六';
						break;
					case 7:
						result = '七';
						break;
					case 8:
						result = '八';
						break;
					case 9:
						result = '九';
						break;
					default:
						break;
				}
				return result;
			}
		}
	}
</script>

<style lang="less" scoped>
	.outDiv {
		width: 100%;
		height: 100vh;
		background: #fff;

		.main {
			margin-top: 0.3rem;
			padding: 0 0.3rem;

			.cardList {
				.cardItem {
					padding: 0.3rem;
					margin-bottom: 0.3rem;
					width: 100%;
					height: 2.24rem;
					box-shadow: 0 0 0.2rem 0 rgba(204, 204, 204, 0.3);
					border-radius: 0.1rem;
					border: 0.02 solid #EEE;

					.line_1 {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-bottom: 0.2rem;

						b {
							color: #222;
							font-weight: bold;
							font-size: 0.3rem;
						}

						span {
							display: inline-block;
							width: 1.9rem;
							height: 0.5rem;
							line-height: 0.5rem;
							text-align: center;
							color: #BBB;
							background: #FAFAFA;
							border-radius: 0.25rem;
							font-size: 0.24rem;
							font-weight: bold;
						}
					}

					.line_2 {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-bottom: 0.2rem;

						.left {
							color: #999;
							font-size: 0.26rem;
							font-weight: 500;
							line-height: 0.37rem;

							span:first-child {
								margin-right: 0.62rem;
							}
						}
							.imgIcon {
							width: 0.24rem;
							height: 0.24rem;
						}
					}

					.line_3 {
						color: #999;
						font-size: 0.26rem;
						font-weight: 500;
						line-height: 0.37rem;

						span:first-child {
							margin-right: 0.2rem;
						}
					}
				}
			}
		}
	}


</style>
